$.ajax({
		url:"../../room/all",
		type:"get",
		dataType:"json",
		success:function(data){
			var content = "";
			for (var i = 0; i < data.length; i++) {
				room=data[i];
				content +='<tr>'
						+'<td>'+room.roomtype.type+'</td>'
						+'<td>'+room.roomnum+'</td>'
						+'<td>'+room.location+'</td>'
						+'<td>'+room.phone+'</td>'
						+'<td>'+room.cut+'</td>'
						+'<td>'+room.hot+'</td>';
						if(room.status==0){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm" onclick="updateRoomStatus('+room.room_id+')">空闲</a>'
									+'</td>';
						}else if(room.status==1){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm layui-btn-normal"   onclick="updateRoomStatus('+room.room_id+')">已住</a>'
									+'</td>';
						}else if(room.status==2){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-danger layui-btn-sm" onclick="updateRoomStatus('+room.room_id+')">维修中</a>'
									+'</td>';
						}else if(room.status==3){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm layui-btn-warm" onclick="updateRoomStatus('+room.room_id+')">已预订</a>'
									+'</td>';
						}
				content	+='<td>'
						+'<a class="layui-btn layui-btn-sm" onclick="showFacility('+room.room_id+')">设备设施</a>'
						+'</td>'
						+'<td>'
						+'<a class="layui-btn layui-btn-sm" onclick="deleteRoom('+room.room_id+')"><i class="layui-icon"></i>删除</a>'
						+'<a class="layui-btn layui-btn-sm" onclick="updateRoom('+room.room_id+')"><i class="layui-icon"></i>修改</a>'
						+'</td>'
						+'</tr>';
				
				
				
			}
			
			$("#searchResult").html(content);
			
			
		}

		
		
		
	});






















function searchRoom(){
	$.ajax({
		url:"../../room/search",
		type:"post",
		dataType:"json",
		data:{
			roomnum:$("#roomnum").val(),
			roomtype_id:$("#roomtype_id").val(),
			status:$("#status").val()
			
		},
		success:function(data){
			var content = "";
			var student=null;
			for (var i = 0; i < data.length; i++) {
				room=data[i];
				content +='<tr>'
						+'<td>'+room.roomtype.type+'</td>'
						+'<td>'+room.roomnum+'</td>'
						+'<td>'+room.location+'</td>'
						+'<td>'+room.phone+'</td>'
						+'<td>'+room.cut+'</td>'
						+'<td>'+room.hot+'</td>';
						if(room.status==0){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm" onclick="updateRoomStatus('+room.room_id+')">空闲</a>'
									+'</td>';
						}else if(room.status==1){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm layui-btn-normal"   onclick="updateRoomStatus('+room.room_id+')">已住</a>'
									+'</td>';
						}else if(room.status==2){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-danger layui-btn-sm" onclick="updateRoomStatus('+room.room_id+')">维修中</a>'
									+'</td>';
						}else if(room.status==3){
							content	+='<td>'
									+'<a class="layui-btn layui-btn-sm layui-btn-warm" onclick="updateRoomStatus('+room.room_id+')">已预订</a>'
									+'</td>';
						}
				content	+='<td>'
					+'<a class="layui-btn layui-btn-sm" onclick="showFacility('+room.room_id+')">设备设施</a>'
					+'</td>'
					+'<td>'
					+'<a class="layui-btn layui-btn-sm" onclick="deleteRoom('+room.room_id+')"><i class="layui-icon"></i>删除</a>'
					+'<a class="layui-btn layui-btn-sm" onclick="updateRoom('+room.room_id+')"><i class="layui-icon"></i>修改</a>'
					+'</td>'
					+'</tr>';
			
				
				
				
			}
			
			$("#searchResult").html(content);
			
			
		}

		
		
		
	});
	
	
	
}





function showFacility(room_id) {
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "设备设施",
			type: 2,
			area: ['70%', '60%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'facilitys.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(room_id)
			}
		});
	});
}


///删除房间
function deleteRoom(room_id){
	$.ajax({
		url:"../../room/delete",
		type:"post",
		dataType:"json",
		
		data:{
			"room_id":room_id
		},
		success:function(data){
			if(data==0){
				alert("删除失败,房间内尚有客人");
				location.reload();
			}else{
				
				location.reload();
			}
			
			
		}
	});
}
//加载房间类型选项
function loadRoomTypeSelect(){
	$.ajax({
		url:"../../roomtype/all",
		type:"get",
		dataType:"json",
		success:function(data){
			//为房间类型添加选项
			var selectItems = "";
			selectItems += '<option value="0"></option></br>';
			for (var i = 0; i < data.length; i++) {
				var roomtype = data[i];
				
				selectItems += '<option value="'+roomtype.roomtype_id+'">'+roomtype.type+'</option></br>';
				
				
			}
			
			$("#roomtype_id").html(selectItems);
		}

		
		
		
	});
}
loadRoomTypeSelect();



//修改房间状态
function updateRoomStatus(room_id){
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "修改房间状态",
			type: 2,
			area: ['70%', '60%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'roomStatus.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(room_id)
			}
		});
	});
	
}


//修改房间信息
function updateRoom(room_id) {
	layui.use('layer', function() {
		var layer = layui.layer;
		//iframe层-父子操作
		b1s = layer.open({
			title: "修改房间信息",
			type: 2,
			area: ['50%', '65%'],
			scrollbar: true, //默认：true,默认允许浏览器滚动，如果设定scrollbar: false，则屏蔽
			maxmin: true,
			content: 'updateRoom.html',
			success: function(layero, index) {
				var iframe = window['layui-layer-iframe' + index];
				iframe.child(room_id)
			}
		});
	});
}



